package com.mingmen.supplier.activity;


import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.mingmen.supplier.R;
import com.mingmen.supplier.adapter.CancelShopDetailAdapter;
import com.mingmen.supplier.adapter.CommodityAdapter;
import com.mingmen.supplier.adapter.NewOrderDetailAdapter;
import com.mingmen.supplier.adapter.YiWcnChengAdapter;
import com.mingmen.supplier.base.BaseBean;
import com.mingmen.supplier.definerecycleview.SwipeRecyclerView;
import com.mingmen.supplier.defineview.FullyLinearLayoutManager;
import com.mingmen.supplier.http.callback.StringCallback;
import com.mingmen.supplier.httpconfig.HttpResponse;
import com.mingmen.supplier.immersionbar.ImmersionBar;
import com.mingmen.supplier.model.NewOrderDetailModel;
import com.mingmen.supplier.util.GsonUtil;
import com.mingmen.supplier.util.MyStringUtils;
import com.mingmen.supplier.util.SharePreferenceUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class NewYiWanChengDetailActivity extends AppCompatActivity implements CommodityAdapter.OnItemClickListener {

    //返回按钮
    @BindView(R.id.text_return)
    TextView textReturn;

    @BindView(R.id.layout_Distribution)
    LinearLayout layout_Distribution;

    @BindView(R.id.recycle_product)
    RecyclerView recycle_product;
    YiWcnChengAdapter yiWcnChengAdapter;

    String token;
    String billId;
    @BindView(R.id.restaurantName)
    TextView restaurantName;
    @BindView(R.id.address)
    TextView address;
    @BindView(R.id.orderDate)
    TextView orderDate;
    @BindView(R.id.shipping)
    TextView shipping;
    @BindView(R.id.total)
    TextView total;
    @BindView(R.id.applyMoney)
    TextView applyMoney;
    @BindView(R.id.text_billId)
    TextView text_billId;
    List<NewOrderDetailModel.DataBean.BillDetailsBean> dataBeanList = new ArrayList<>();
    List<NewOrderDetailModel.DataBean.EvalListBean> evalListBeanList = new ArrayList<>();

    String myShipping = "";
    String shippingFee = "";
    @BindView(R.id.linear_return)
    LinearLayout linear_return;
    String partCancelFlag;
    String partArriveFlag;
    String partRefuseFlag;
    @BindView(R.id.score)
    TextView score;
    String str_Score;
    String getStr_Score;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yiwancheng_detail);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f)
                .init();
        token = (String) SharePreferenceUtil.get(this, "token", "");
        billId = getIntent().getStringExtra("billId");
        partCancelFlag = getIntent().getStringExtra("partCancelFlag");
        partArriveFlag = getIntent().getStringExtra("partArriveFlag");
        partRefuseFlag = getIntent().getStringExtra("partRefuseFlag");

        recycle_product.setLayoutManager(new LinearLayoutManager(this));
        recycle_product.setNestedScrollingEnabled(false);
//        recycle_product.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        yiWcnChengAdapter = new YiWcnChengAdapter(this, dataBeanList);
        recycle_product.setAdapter(yiWcnChengAdapter);


        HttpResponse.getOrder(token, billId, partCancelFlag, partArriveFlag, partRefuseFlag, new StringCallback(this) {
            @Override
            public void onSuccess(String s, Call call, Response response) {

                Log.d("getOrdergetOrder", s);

                BaseBean baseBean = new BaseBean();
                baseBean = GsonUtil.GsonToBean(s, BaseBean.class);
                if (baseBean.getCode() == 0) {
                    NewOrderDetailModel newOrderDetailModel = new NewOrderDetailModel();
                    newOrderDetailModel = GsonUtil.GsonToBean(s, NewOrderDetailModel.class);
                    restaurantName.setText(newOrderDetailModel.getData().get(0).getRestaurantName());
                    address.setText(newOrderDetailModel.getData().get(0).getAddress());
                    orderDate.setText(newOrderDetailModel.getData().get(0).getOrderDate());
                    if (newOrderDetailModel.getData().get(0).getShipping().equals("0")) {
                        shipping.setText("线下自取");
                    } else {
                        shipping.setText("商家配送");
                    }
                    total.setText(newOrderDetailModel.getData().get(0).getTotal() + "元");
                    applyMoney.setText("(￥" + newOrderDetailModel.getData().get(0).getApplyMoney() + "+配送费: " + "￥" + newOrderDetailModel.getData().get(0).getShippingFee() + "元" + ")");
                    text_billId.setText("订单编号: " + newOrderDetailModel.getData().get(0).getBillId());
                    dataBeanList.addAll(newOrderDetailModel.getData().get(0).getBillDetails());
                    myShipping = newOrderDetailModel.getData().get(0).getShipping();
                    shippingFee = newOrderDetailModel.getData().get(0).getShippingFee();
                    yiWcnChengAdapter.setDataList(dataBeanList);
                    score.setText(newOrderDetailModel.getData().get(0).getScore() + "");
                    str_Score = MyStringUtils.beanToString(newOrderDetailModel.getData().get(0).getEvalList());
                    getStr_Score = newOrderDetailModel.getData().get(0).getScore() + "";
                } else {
                    Toast.makeText(NewYiWanChengDetailActivity.this, baseBean.getMessage() + "", Toast.LENGTH_SHORT).show();
                }

            }
        });


    }


    @OnClick({R.id.text_return, R.id.layout_Distribution, R.id.linear_return})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {

            case R.id.text_return:
            case R.id.linear_return:
                finish();
                break;

            case R.id.layout_Distribution:
                if (str_Score.length() < 5) {
                    Toast.makeText(this, "当前无评价", Toast.LENGTH_SHORT).show();
                } else {
                    intent = new Intent(NewYiWanChengDetailActivity.this, PingScoreActivity.class);
                    intent.putExtra("str_Score", str_Score);
                    intent.putExtra("getStr_Score", getStr_Score);
                    startActivity(intent);

                }


                break;
        }
    }


    @Override
    public void onItemClickListener(View view, int pos, List<String> myLiveList) {

    }


}




